package com.xxdemo.quickstart;

import com.xxdemo.quickstart.util.AbstractIdNumberRange;
import com.xxdemo.quickstart.util.NumberRange;

public class CustomerIdNumberRange extends AbstractIdNumberRange<Long> implements NumberRange<Long> {
    private final Long start;
    private final Long width;

    protected CustomerIdNumberRange(long start, long width) {
        this.start = start;
        this.width = width;
    }

    @Override
    public Long rangeStart() {
        return start;
    }

    @Override
    public Long rangeWidth() {
        return width;
    }

    /**
     * 使用任意两个数字创建一个数值区间NumberRange对象
     *
     * @param num1 允许num1大于或小于num2
     * @param num2 允许num1大于或小于num2
     * @return NumberRange对象
     */
    public static CustomerIdNumberRange betweenTwoNumbers(long num1, long num2) {
        long maxId = Math.max(num1, num2);
        long minId = Math.min(num1, num2);
        long rangeWidth = maxId - minId + 1;
        return new CustomerIdNumberRange(minId, rangeWidth);
    }
}
